const express = require('express'); //引入express模块
const db = require('../db'); //引入user模块

//路由中间件
const router = express.Router();
module.exports = router;


router.post('/', async (req, res) => {
    const {
        name,
        gender,
        nation,
        id_number,
        Student_number,
        cell_phone_number,
        QQ_number,
        college,
        class1,
        Home_address
    } = req.body

    // console.log('req.body',req.body)

    // console.log(  name,
    //     gender,
    //     nation,
    //     id_number,
    //     Student_number,
    //     cell_phone_number,
    //     QQ_number,
    //     college,
    //     class1,
    //     Home_address);

    const sql = `insert into hu_ji_xin_xi
    (name,gender,nation,id_number,Student_number,
        cell_phone_number,QQ_number,college,class1,
        Home_address) values('${name}','${gender}',
        '${nation}','${id_number}','${Student_number}',
        '${cell_phone_number}','${QQ_number}','${college}',
        '${class1}','${Home_address}')`


    const data = await db(sql);
    if (data.insertId) {
        //统一前后端数据格式
        res.send({
            code: 200
        })
    } else {
        res.send({
            code: 400
        })
    }
});